package com.itheima_05;

public class MyThread extends Thread {
    private static int ticket = 100;

    @Override
    public void run() {
        while (true) {
            if (method()) {
                break;
            }
        }
    }

    // public synchronized boolean method() {//this
    public static synchronized boolean method() {//类名.class
        if (ticket > 0) {
            System.out.println(Thread.currentThread().getName() + "在买票,还剩" + ticket + "张");
            ticket--;
            return false;
        } else {
            return true;
        }
    }
}
